package com.central.apps.handler;

import cn.hutool.core.map.MapUtil;
import com.central.app.common.util.BLuntil;
import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import com.central.apps.handler.until.DateUtiles;
import com.central.bizcommon.model.flow.FlowNode;
import com.central.bizcommon.model.flow.FlowOpinion;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Component
@Log4j2
public class OldWorkorderHandler extends LvBaseHandler {
    @Autowired
    private HandlerService handlerService;

    public Object operate(String app, String type, Map<String, Object> params) throws Exception {
        if (type.equals("delectwo")) {
            String id = MapUtil.getStr(params, "ID");
            List<Map<String, Object>> workorderList = handlerService.findBySql("select * from bl_workorder  where id =" + id + "");
            String wonum = MapUtil.getStr(workorderList.get(0), "WONUM");
            String jpnum = MapUtil.getStr(workorderList.get(0), "JPNUM");
            if (null != wonum && null != jpnum) {
                handlerService.updateBySql("delete from bl_workordertask where wonum = '" + wonum + "' and jpnum ='" + jpnum + "' ");
                handlerService.updateBySql("delete from bl_wplabor where wonum = '" + wonum + "'and jpnum ='" + jpnum + "'");
                handlerService.updateBySql("delete from bl_wpmaterial where wonum = '" + wonum + "'and jpnum ='" + jpnum + "'");
                return "删除成功！";

            }

        }
        //工单选择缺陷提报单   只可选择状态为 ‘已审核’的自修、报修 或 提报单类型 为整改的单据
        if ("getDefectReport".equals(type)) {
            String deptcode = MapUtils.getString(params, "deptcode");
            String sql = " select a.REPORTNUM,a.reportname,a.assetnum,asset.equipmentdescribe,asset.assetlocation,loca.description from  " +
                    "  ( select *from bl_defectreport where left(deptcode ,6)=left('" + deptcode + "',6)  " +
                    "  AND STATUS IN ('已审核','已指派')  or type='整改' ) a  " +
                    " left join bl_asset asset on asset.assetnum=a.assetnum " +
                    " left join bl_locationmanagement loca on asset.assetlocation=loca.location " +
                    "  where a.flag is null and a.apptype='提报'   ORDER BY  a.createTime  desc";

            return BLuntil.toPage(params, handlerService, sql);
        }
        if ("getWorkGroup".equals(type)) {
            String deptcode = MapUtils.getString(params, "deptcode");
            String sql = "select * from bl_workgroup where parent in (select groupnum from bl_workgroup where deptcode ='" + deptcode + "')";
            return BLuntil.toPage(params, handlerService, sql);
        }
        if ("getWorkGroups".equals(type)) {
            String area = MapUtils.getString(params, "area");
            String sql = "select * from bl_workgroup where left(deptcode,6)='" + area + "' ";
            return BLuntil.toPage(params, handlerService, sql);
        }


        return null;
    }

    @Override
    public void afterSave(String app, String objName, Map<String, Object> data, boolean isUpdate) throws Exception {
        //保存时 将维修工段的值赋予deptcode
//        String wonum = MapUtil.getStr(data, "WONUM");
//        String maintenancesection =MapUtils.getString(data,"maintenancesection");
//        handlerService.updateBySql("UPDATE bl_workorder set deptcode='"+maintenancesection+"' where wonum='"+wonum+"'");
        if("gq_workorder".equals(objName)){
            String jpnum = MapUtil.getStr(data, "jpnum");
            String wonum = MapUtil.getStr(data, "wonum");
            if(jpnum!=null){
                List<Map<String, Object>> datas = new ArrayList<>();
                // 1.查询作业任务信息
                List<Map<String, Object>> list = handlerService.findBySql("select jobtask, abstract from gq_jobtask t where t.jpnum = '" + jpnum + "'");
                if (CollectionUtils.isNotEmpty(list)) {
                    // 组织插入数据
                    for (Map<String, Object> map : list) {
                        Map<String, Object> insertMap = new HashMap<>();
                        insertMap.put("tasknum", map.get("jobtask"));// 任务编码
                        insertMap.put("taskdesc", map.get("abstract"));// 任务描述
                        insertMap.put("wonum", wonum);// 工单编码
                        datas.add(insertMap);
                    }

                    // 插入计划作业任务信息
                    handlerService.batchInsert("wptaskApp", "gq_wptask", datas);
                    //插入实际工作子表
                    handlerService.batchInsert("wptaskApp", "gq_acttask", datas);
                }

                // 2.查询作业计划-人员信息
                list = handlerService.findBySql("select labor, quantity, craft from gq_joblabor t where t.jpnum = '" + jpnum + "'");

                // 组织插入数据
                if (CollectionUtils.isNotEmpty(list)) {
                    datas = new ArrayList<>();
                    for (Map<String, Object> map : list) {
                        Map<String, Object> insertMap = new HashMap<>();
                        insertMap.put("labor", map.get("labor"));// 员工ID
                        insertMap.put("quantity", map.get("quantity"));// 数量
                        insertMap.put("craft", map.get("craft"));// 工种
                        insertMap.put("wonum", wonum);// 工单编码
                        datas.add(insertMap);
                    }

                    // 插入作业人员信息
                    handlerService.batchInsert("wplaborApp", "gq_wplabor", datas);
                }

                // 3.查询作业计划-物料信息
                list = handlerService.findBySql("select itemnum, itemqty, unitcost, linecost from gq_jobitem t where t.jpnum = '" + jpnum + "'");

                // 组织插入数据
                if (CollectionUtils.isNotEmpty(list)) {
                    datas = new ArrayList<>();
                    for (Map<String, Object> map : list) {
                        Map<String, Object> insertMap = new HashMap<>();
                        insertMap.put("itemnum", map.get("itemnum"));// 物料编码
                        insertMap.put("itemdesc", "");// 物料名称
                        insertMap.put("itemqty", map.get("itemqty"));// 数量
                        insertMap.put("unitcost", map.get("unitcost"));// 单位成本
                        insertMap.put("linecost", map.get("linecost"));// 行成本
                        insertMap.put("wonum", wonum);// 工单编码
                        datas.add(insertMap);
                    }

                    // 插入作业人员信息
                    handlerService.batchInsert("wpmaterialApp", "gq_wpmaterial", datas);
                }
            }

        }

        super.afterSave(app, objName, data, isUpdate);
    }

    //保存前调用
    public void beforSave(String app, String objName, Map<String, Object> data, boolean isUpdate) throws Exception {



        //如果是修改，如果作业计划编号不为空，先删除原来的作业计划编号插入的人员，物料，作业任务数据。保存后代码那边添加最新的
        if("gq_workorder".equals(objName)&&isUpdate){
            //String jpnum = MapUtil.getStr(data, "jpnum");
            String wonum = MapUtil.getStr(data, "wonum");

            //查询原作业计划编号
            String sql = "select jpnum from gq_workorder where wonum = "+wonum;
            List<Map<String, Object>> workList = handlerService.findBySql(sql);

            if(CollectionUtils.isNotEmpty(workList)&&workList.get(0).get("jpnum")!=null){
                String sql2 = "delete from gq_wptask where wonum = "+wonum;//计划作业任务
                handlerService.updateBySql(sql2);
                String sql3 = "delete from gq_wplabor where wonum = "+wonum;//人员信息
                handlerService.updateBySql(sql3);
                String sql4 = "delete from gq_wpmaterial where wonum = "+wonum;//物料信息
                handlerService.updateBySql(sql4);
                String sql5 = "delete from gq_acttask where wonum = "+wonum;//实际工作任务
                handlerService.updateBySql(sql5);
            }


        }
//        String wonum = MapUtil.getStr(data, "WONUM");
//        String status = MapUtil.getStr(data, "status");
//        String jpnum = MapUtil.getStr(data, "JPNUM");
//        if (jpnum != null) {
//            List<Map<String, Object>> workorderList = handlerService.findBySql("select * from bl_workorder where WONUM = '" + wonum + "'");
//            if (workorderList.size() > 0) {
//                String jpnum2 = MapUtil.getStr(workorderList.get(0), "JPNUM");
//                if (jpnum2 == null) {
//                    String sql1 = "select " + wonum + ",deptcode,workmethod,jpnum from bl_jobtask where jpnum='" + jpnum + "'";
//                    String sql2 = "insert into bl_workordertask(wonum,deptcode,content,jpnum) ";
//                    handlerService.updateBySql(sql2 + sql1);
//
//                    //复制计划人员
//                    String sql3 = "select deptcode," + wonum + ",CRAFT,craftdesc,craftquantity,TASKID,TYPE,JOBPLANID from bl_wplabor where jobplanid='" + jpnum + "'";
//                    String sql4 = "insert into bl_wplabor(deptcode,wonum,CRAFT,craftdesc,craftquantity,TASKID,TYPE,jpnum) ";
//                    handlerService.updateBySql(sql4 + sql3);
//
//                    //复制计划物料
//                    String sql5 = "select deptcode," + wonum + ",ITEMNUM,ITEMQTY,location,TYPE,JOBPLANID from bl_wpmaterial where jobplanid='" + jpnum + "'";
//                    String sql6 = "insert into bl_wpmaterial(deptcode,wonum,ITEMNUM,ITEMQTY,location,TYPE,jpnum) ";
//                    handlerService.updateBySql(sql6 + sql5);
//                }
//                Boolean isJpnum = jpnum2.equals(jpnum);
//                if (isJpnum) {
//                } else {
//                    handlerService.updateBySql("delete from bl_workordertask where wonum = '" + wonum + "' and jpnum ='" + jpnum2 + "' ");
//                    String sql1 = "select '" + wonum + "',deptcode,workmethod,jpnum from bl_jobtask where jpnum='" + jpnum + "'";
//                    String sql2 = "insert into bl_workordertask(wonum,deptcode,content,jpnum) ";
//                    handlerService.updateBySql(sql2 + sql1);
//
//                    //复制计划人员
//                    handlerService.updateBySql("delete from bl_wplabor where wonum = '" + wonum + "'and jpnum ='" + jpnum2 + "'");
//                    String sql3 = "select deptcode,'" + wonum + "',CRAFT,craftdesc,craftquantity,TASKID,TYPE,JOBPLANID from bl_wplabor where jobplanid='" + jpnum + "'";
//                    String sql4 = "insert into bl_wplabor(deptcode,wonum,CRAFT,craftdesc,craftquantity,TASKID,TYPE,jpnum) ";
//                    handlerService.updateBySql(sql4 + sql3);
//
//                    //复制计划物料
//                    handlerService.updateBySql("delete from bl_wpmaterial where wonum = '" + wonum + "'and jpnum ='" + jpnum2 + "'");
//                    String sql5 = "select deptcode,'" + wonum + "',ITEMNUM,ITEMQTY,location,TYPE,JOBPLANID from bl_wpmaterial where jobplanid='" + jpnum + "'";
//                    String sql6 = "insert into bl_wpmaterial(deptcode,wonum,ITEMNUM,ITEMQTY,location,TYPE,jpnum) ";
//                    handlerService.updateBySql(sql6 + sql5);
//
//                }
//
//            }
//        } else {
//
//        }


    }

    public void addFlowVar(String app, Long id, FlowNode flowNode, FlowOpinion op, Map<String, Object> variables) throws Exception {
        List<Map<String, Object>> workorderList = handlerService.findBySql("select UDWOTYPE from bl_workorder where id=" + id);
        String UDWOTYPE = MapUtil.getStr(workorderList.get(0), "UDWOTYPE");
        if (null != UDWOTYPE) {
            if (flowNode.getId().equals("zxgd")) {
                if (UDWOTYPE.equals("缺陷工单")) {
                    variables.put("isqq", 1);
                } else {
                    variables.put("isqq", 0);
                }
            }
        }
    }

    /**
     * 工单流程获取对应的三种角色:
     * 1.车间主任
     * 2.缺陷工单创建人
     * 3.点检员
     */

    public String addFlowCandidate(String app, Long id, FlowNode flowNode, Map<String, Object> vars) throws Exception {
        String executer = null;
        Map<String, String> map = new HashMap<>();
        map.put("sh", " and (position like '%车间主任%' or position like '%主管%') ");
        map.put("djys", " and position like '%点检员%' ");
        map.put("czys", " select u.username from  sys_user u LEFT JOIN bl_defectreport d on u.id = d.createuser where ");
        map.put("zxgd", " and position like '%维修负责人%' ");
        List<Map<String, Object>> defectreport = handlerService.findBySql("select deptcode,REPORTNUM,maintenanceprincipal,createuser,acceptanceperson from bl_workorder where id=" + id);
        String deptcode = MapUtil.getStr(defectreport.get(0), "deptcode");
        String REPORTNUM = MapUtil.getStr(defectreport.get(0), "REPORTNUM");
        //拿到维修负责人的信息
        String maintenanceprincipal = MapUtil.getStr(defectreport.get(0), "maintenanceprincipal");
        //拿到创建人的信息
        String createuser = MapUtil.getStr(defectreport.get(0), "createuser");
        List<Map<String, Object>> personlist = handlerService.findBySql("select username from sys_user where id=" + createuser);
        String createuserdesc = MapUtils.getString(personlist.get(0), "username");
        //拿到username
        StringBuffer sbf = new StringBuffer();
        if (StringUtils.isNotBlank(map.get(flowNode.getId()))) {
            //拿到deptcode

            if (flowNode.getId().equals("czys")) {
                sbf.append(map.get(flowNode.getId()) + " d.reportnum = '" + REPORTNUM + "'");
            } else {
                sbf.append("select u.username from bl_person p left join sys_user u on p.personid = u.worknumber where LEFT(p.deptcode,6)=LEFT('" + deptcode + "',6)" + MapUtils.getString(map, flowNode.getId()));
            }
            List<Map<String, Object>> persons = handlerService.findBySql(sbf.toString());
            if (CollectionUtils.isNotEmpty(persons)) {
                //人员以逗号隔开
                StringJoiner sj = new StringJoiner(",", "", "");
                for (Map<String, Object> username : persons) {
                    sj.add(MapUtils.getString(username, "username"));
                }
                executer = sj.toString();
                log.info("人员查到了" + executer);
            }


        }
        if ("jxbz".equals(flowNode.getId())) {
            if (maintenanceprincipal != null && !"".equals(maintenanceprincipal)) {
                executer = maintenanceprincipal;
            }
        }
        //拿到验收负责人的信息
        String acceptanceperson = MapUtil.getStr(defectreport.get(0), "acceptanceperson");
        //执行工单的节点
        if ("zxgd".equals(flowNode.getId())) {
            //判断执行工单节点是否有人，如果有人，就是维修负责人
            if (!"".equals(maintenanceprincipal)) {
                executer = maintenanceprincipal;
                //执行工单节点如果没人就是创建人
            } else {
                executer = createuserdesc;
            }
        }
        //验收工单的节点
        if ("czys".equals(flowNode.getId()) || "djys".equals(flowNode.getId())) {
            //判断验收工单节点是否有人，如果有人，就是验收负责人
            if (!"".equals(acceptanceperson)) {
                executer = acceptanceperson;
                //验收工单节点如果没人就是执行人
            } else {
                if (!"".equals(maintenanceprincipal)) {
                    executer = maintenanceprincipal;
                    //执行工单节点如果没人就是创建人
                } else {
                    executer = createuserdesc;
                }
            }
        }
        return executer;
    }

    @Override
    public void afterExcuteFlow(String app, Long id, FlowNode flowNode, FlowOpinion op, String event) throws Exception {

        //工单完成验收后 同步将检修计划行中的完成情况 修改为 ‘完成’
        if (flowNode.getId().equals("djys") || flowNode.getId().equals("czys")) {//获取节点名称
            //获取当前时间
            SimpleDateFormat sdftime3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String newtime = sdftime3.format(new Date());
            boolean flag = op.isFlag();//是否审核通过
            if (flag) {
                Map<String, Object> map = handlerService.findMainById(app, id);//获取工单主对象
//                String wonum = MapUtils.getString(map,"wonum");//获取工单编号
//                List<Map<String, Object>> planTaskList = handlerService.findBySql("select * from bl_planitems WHERE WONUM='"+wonum+"'");
//                if(planTaskList!=null && planTaskList.size()>0){
//                    planTaskList.get(0).put("isfinish","完成");
//                    planTaskList.get(0).put("finishdate",newtime);
//                    handlerService.update("bl_planitems",planTaskList.get(0));
//                }
                //工单完成验收后，将检修计划行中的完成情况修改为“完成”
                //获取工单的编号
                String WONUM = BLuntil.getParameter(map, "WONUM");
                if (!"".equals(WONUM) && WONUM != null) {
                    handlerService.findBySql("UPDATE bl_planitems SET isfinish ='完成',finishdate='" + newtime + "'  where wonum='" + WONUM + "'");
                }
                //工单验收完成后，缺陷提报状态变更为关闭
                //获取缺陷提报单的编号
                String REPORTNUM = BLuntil.getParameter(map, "REPORTNUM");
                //获取缺陷故障类编号
                String FAILURECODE = BLuntil.getParameter(map, "FAILURECODE");
                //获取故障现象编号
                String PROBLEMCODE = BLuntil.getParameter(map, "PROBLEMCODE");
                //获取故障原因编号
                String FAILUREREASON = BLuntil.getParameter(map, "FAILUREREASON");
                //获取故障措施编号
                String FAILUREMEASURE = BLuntil.getParameter(map, "FAILUREMEASURE");
                //获取实际原因
                String REASONREMARK = BLuntil.getParameter(map, "REASONREMARK");
                //获取解决措施
                String MEASUREREMARK = BLuntil.getParameter(map, "MEASUREREMARK");
                //获取处理完成时间
                String ACTFINISH = BLuntil.getParameter(map, "ACTFINISH");
                if (!"".equals(REPORTNUM) && REPORTNUM != null) {
                    handlerService.updateBySql("UPDATE bl_defectreport set status='关闭',failurecode='" + FAILURECODE + "',phenomenon='" + PROBLEMCODE + "',reason='" + FAILUREREASON + "',measure='" + FAILUREMEASURE + "'," +
                            "     rootcause='" + REASONREMARK + "',process='" + MEASUREREMARK + "',finishdate='" + newtime + "'  where reportnum='" + REPORTNUM + "'");
                }
                handlerService.updateBySql("UPDATE bl_workorder SET ACTFINISH = '" + newtime + "' WHERE id = '" + id + "'");
                String actstart = MapUtil.getStr(map, "ACTSTART");
                if (StringUtils.isNotBlank(actstart)) {
                    String actfinish = MapUtil.getStr(map, "ACTFINISH");
                    long l = DateUtiles.calculatetimeGapMins(actstart, newtime);
                    handlerService.updateBySql("UPDATE bl_workorder SET ACTHOURS = '" + l + "' WHERE id = '" + id + "'");
                }
            }
        }

        if ("jxbz".equals(flowNode.getId())) {
            boolean flag = op.isFlag();//是否提交
            if (flag) {
                //工单提交以后，将车间检修计划的子表的选择状态置为1
                Map<String, Object> map = handlerService.findMainById(app, id);//获取工单主对象
                String fixplanline = MapUtils.getString(map, "fixplanline");//获取车间检修计划行信息的编号
                if (!"".equals(fixplanline) && fixplanline != null) {
                    handlerService.updateBySql("UPDATE bl_planitems SET choiceflag=1  WHERE id='" + fixplanline + "'");
                }

                //获取缺陷提报单的编号
                String REPORTNUM = MapUtils.getString(map, "REPORTNUM");
                if (!"".equals(REPORTNUM) && REPORTNUM != null) {
                    //工单提交后将缺陷提报单状态变更为‘处理中’；
                    handlerService.updateBySql("UPDATE bl_defectreport set status='处理中' where reportnum='" + REPORTNUM + "'");
                    //工单提交后将缺陷提报单状态变更为1
                    handlerService.updateBySql("UPDATE bl_defectreport set flag='1' where reportnum='" + REPORTNUM + "'");
                }

            }
        }


        super.afterExcuteFlow(app, id, flowNode, op, event);
    }

//    @Override
//    public String validateSave(String app, String objName, Map<String, Object> data) throws Exception {
//        //增加限制，工单必须关联检修计划或缺陷，且只能关联一个
//        //进入到工单应用
//        if ("workorderApp".equals(app)){
//            //进入到工单的主表
//            if ("bl_workorder".equals(objName)){
//                //获取到缺陷提报单
//                String REPORTNUM=MapUtils.getString(data,"REPORTNUM");
//                //获取到计划检修信息
//                String fixtext=MapUtils.getString(data,"fixtext");
//                //缺陷提报单和计划检修信息不能同时存在
////                if (!"".equals(REPORTNUM) && !"".equals(fixplanline)){
////                    return "缺陷提报单和计划检修信息只能选择其中一个";
////                }
////                //缺陷提报单和计划检修信息不能同时不存在（必须有一个存在）
////               if ("".equals(REPORTNUM) && "".equals(fixplanline)){
////                   return  "必须选择缺陷提报单和计划检修信息的其中一个";
////               }
//                if ((REPORTNUM!=null || !"".equals(REPORTNUM)) && (fixtext!= null || !"".equals(fixtext))){
//                    return "缺陷提报单和计划检修信息只能选择其中一个";
//                }
//                //缺陷提报单和计划检修信息不能同时不存在（必须有一个存在）
//                if ((REPORTNUM==null || "".equals(REPORTNUM)) && (fixtext== null || "".equals(fixtext))){
//                    return  "必须选择缺陷提报单和计划检修信息的其中一个";
//                }
//
//            }
//        }
//        return super.validateSave(app, objName, data);
//    }
    //    /**
//     * 处理类：保存后调用(会在主表和子表保存前都调用)
//     *
//     * @param app      应用
//     * @param objName  表名
//     * @param data     数据
//     * @param isUpdate 是否是修改：true为修改；false为新增；
//     */
//    public void afterSave(String app, String objName, Map<String, Object> data, boolean isUpdate) throws Exception {
//        String wonum = MapUtil.getStr(data, "WONUM");
//        String status= MapUtil.getStr(data, "status");
//        String jpnum = MapUtil.getStr(data, "JPNUM");
//
//        List<Map<String,Object>> workordertaskList=handlerService.findBySql("select * from bl_workordertask where jpnum = '"+jpnum+"'");
//        if (workordertaskList.size()>0){
//            Map<String,Object> workordertaskMap=workordertaskList.get(0);
//
//        }
////        if (isUpdate) {
////        } else {
//        if (jpnum != null) {
//            //复制计划任务
//            handlerService.updateBySql("delete from bl_workordertask where wonum = '"+wonum+"' ");
//            String sql1 = "select " + wonum + ",deptcode,workmethod,jpnum from bl_jobtask where jpnum='" + jpnum + "'";
//            String sql2 = "insert into bl_workordertask(wonum,deptcode,content,jpnum) ";
//            handlerService.updateBySql(sql2 + sql1);
//
//            //复制计划人员
//            handlerService.updateBySql("delete from bl_wplabor where wonum = '"+wonum+"'");
//            String sql3 = "select deptcode," + wonum + ",CRAFT,craftdesc,craftquantity,TASKID,TYPE,jpnum from bl_wplabor where jobplanid='" + jpnum + "'";
//            String sql4 = "insert into bl_wplabor(deptcode,wonum,CRAFT,craftdesc,craftquantity,TASKID,TYPE,jpnum) ";
//            handlerService.updateBySql(sql4 + sql3);
//
//            //复制计划物料
//            handlerService.updateBySql("delete from bl_wpmaterial where wonum = '"+wonum+"'");
//            String sql5 = "select deptcode," + wonum + ",ITEMNUM,ITEMQTY,location,TYPE,jpnum from bl_wpmaterial where jobplanid='" + jpnum + "'";
//            String sql6 = "insert into bl_wpmaterial(deptcode,wonum,ITEMNUM,ITEMQTY,location,TYPE,jpnum) ";
//            handlerService.updateBySql(sql6 + sql5);
//        }
//
////    }
//        if (isUpdate && status!=null) {
//            if (status.equals("草稿")) {
//                //任务
//                handlerService.updateBySql("delete from bl_workorderactualtask where wonum = '"+wonum+"'");
//                String sql1 = "select TASKID,wonum,deptcode,content from bl_workordertask where wonum='" + wonum + "'";
//                String sql2 = "insert into bl_workorderactualtask(TASKID,wonum,deptcode,content) ";
//                handlerService.updateBySql(sql2 + sql1);
//
//                //人员
//                handlerService.updateBySql("delete from bl_labtrans where wonum = '"+wonum+"'");
//                String sql3 = "select deptcode,wonum,CRAFT,craftdesc,craftquantity,TASKID,TYPE from bl_wplabor where wonum='" + wonum + "'";
//                String sql4 = "insert into bl_labtrans(deptcode,wonum,CRAFT,craftdesc,craftquantity,TASKID,TYPE) ";
//                handlerService.updateBySql(sql4 + sql3);
//
//                //物料
//                handlerService.updateBySql("delete from bl_materials where wonum = '"+wonum+"'");
//                String sql5 = "select deptcode,wonum,ITEMNUM,ITEMQTY,location,TYPE from bl_wpmaterial where wonum='" + wonum + "'";
//                String sql6 = "insert into bl_materials(deptcode,wonum,ITEMNUM,ITEMQTY,location,TYPE) ";
//                handlerService.updateBySql(sql6 + sql5);
//
//            }
//        }
//
//    }

}
